/*
 * Copyright 2011-2012 Redia A/S
 * 
 * This file is part of Redias Library App for Android.
 *
 *  Redia Library App for Android is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Redia Library App for Android is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with Redia Library App for Android.  If not, see <http://www.gnu.org/licenses/>.
 */
package dk.redia.libraryapp.model;

import java.util.Date;

import android.os.Parcel;
import android.os.Parcelable;
import dk.redia.lib.utils.DateUtils;

public class Reservation implements Parcelable {
	private String reservationId = "";
	private boolean remoteLoan;
	private String author = "";
	private boolean hasPickupExpireDate;
	private Date pickupExpireDate = new Date();
	private boolean hasSelfServicePickupNo;
	private String selfServicePickupNo = "";
	private String reservationPickupBranch = "";
	private boolean hasQueueNo;
	private String queueNo = "";
	private boolean reservationOk;
	private String title;
	
	public String toString() {
		return "{Reservation id=" + reservationId + ", author=" + author + "}";
	}
	
	public String getReservationId() {
		return reservationId;
	}
	public void setReservationId(String reservationId) {
		this.reservationId = reservationId;
	}
	public boolean isRemoteLoan() {
		return remoteLoan;
	}
	public void setRemoteLoan(boolean remoteLoan) {
		this.remoteLoan = remoteLoan;
	}
	public String getAuthor() {
		return author;
	}
	public void setAuthor(String author) {
		this.author = author;
	}

	public void setHasPickupExpireDate(boolean hasPickupExpireDate) {
		this.hasPickupExpireDate = hasPickupExpireDate;
	}
	public boolean isReservationOk() {
		return reservationOk;
	}
	public void setReservationOk(boolean reservationOk) {
		this.reservationOk = reservationOk;
	}
	public String getQueueNo() {
		return queueNo;
	}
	public void setQueueNo(String queueNo) {
		this.queueNo = queueNo;
	}
	public String getSelfServicePickupNo() {
		return selfServicePickupNo;
	}
	public void setSelfServicePickupNo(String selfServicePickupNo) {
		this.selfServicePickupNo = selfServicePickupNo;
	}
	public boolean hasSelfServicePickupNo() {
		return hasSelfServicePickupNo;
	}
	public void setHasSelfServicePickupNo(boolean hasSelfServicePickupNo) {
		this.hasSelfServicePickupNo = hasSelfServicePickupNo;
	}
	public String getReservationPickupBranch() {
		return reservationPickupBranch;
	}
	public void setReservationPickupBranch(String reservationPickupBranch) {
		this.reservationPickupBranch = reservationPickupBranch;
	}
	public boolean hasQueueNo() {
		return hasQueueNo;
	}
	public void setHasQueueNo(boolean hasQueueNo) {
		this.hasQueueNo = hasQueueNo;
	}
	public Date getPickupExpireDate() {
		return pickupExpireDate;
	}
	public void setPickupExpireDate(Date pickupExpireDate) {
		this.pickupExpireDate = pickupExpireDate;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	
	public String getTitle() {
		return title;
	}

	public int describeContents() {
		return 0;
	}

	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(reservationId);
		dest.writeString(new String(remoteLoan ? "1" : "0"));
		dest.writeString(author);
		dest.writeString(hasPickupExpireDate ? "1" : "0");
		dest.writeInt(DateUtils.getUnixTime(pickupExpireDate));
		dest.writeString(hasSelfServicePickupNo ? "1" : "0");
		dest.writeString(selfServicePickupNo);
		dest.writeString(reservationPickupBranch);
		dest.writeString(hasQueueNo ? "1" : "0");
		dest.writeString(queueNo);
		dest.writeString(reservationOk ? "1" : "0");
		dest.writeString(title);
	}
	
	public static final Parcelable.Creator<Reservation> CREATOR = new Parcelable.Creator<Reservation>() {

		public Reservation createFromParcel(Parcel source) {
			
			Reservation r = new Reservation();
			r.reservationId = source.readString();
			r.remoteLoan = source.readString().equals("1");
			r.author = source.readString();
			r.hasPickupExpireDate = source.readString().equals("1");
			r.pickupExpireDate = new Date(new Long(source.readInt()));
			r.hasSelfServicePickupNo = source.readString().equals("1");
			r.selfServicePickupNo = source.readString();
			r.reservationPickupBranch = source.readString();
			r.hasQueueNo = source.readString().equals("1");
			r.queueNo = source.readString();
			r.reservationOk = source.readString().equals("1");
			r.title = source.readString();
			
			return r;
		}

		public Reservation[] newArray(int size) {
			return new Reservation[size];
		}
		
	};

	public boolean hasPickupExpireDate() {
		return hasPickupExpireDate;
	}
	
}
